﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using PIT.Labs.SharePoint.Extensions.Helper;

namespace PIT.Labs.SharePoint.Extensions
{
    /// <summary>
    /// Defines the friendly name for a property of a Web Parts control.
    /// </summary>
    public sealed class LocalizedWebDisplayNameAttribute : WebDisplayNameAttribute
    {

        private String _resourceFile;

        /// <summary>
        /// Initializes a new instance of the <see cref="LocalizedWebDisplayNameAttribute"/> class with a specified display name.
        /// </summary>
        /// <param name="displayName">The friendly display name.</param>
        /// <param name="resourceFile">The base file name of the language resource file containing a localized string value.
        /// For example, if you have a series of resource files named <c>myresources.en-us.resx</c>, <c>myresources.es-es.resx</c>, <c>myresources.de-de.resx</c>, and so on, the value to pass in this parameter is <c>myresources</c>.
        /// </param>
        public LocalizedWebDisplayNameAttribute(String displayName, String resourceFile)
            : base(displayName)
        {
            this._resourceFile = resourceFile;
        }

        /// <summary>
        /// Gets the name of a property to display.
        /// </summary>
        public override String DisplayName
        {
            get
            {
                this.DisplayNameValue = SPUtilityHelper.GetLocalizedString(base.DisplayName, this._resourceFile);
                return base.DisplayName;
            }
        }
    }
}
